/**
 *  Copyright(C) 2007 Juri Strumpflohner
 *  All rights reserved
 *
 *  Created: 07.08.2007
*/

package org.aroundme.sandbox;

import java.text.ParseException;
import java.util.List;

import org.aroundme.model.CategoryName;
import org.aroundme.model.Place;
import org.aroundme.utility.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;

public class TestClass {
	
	public static void main(String[] args) throws ParseException {
		CategoryName name = CategoryName.BANKS;
		System.out.println(name);
		
		
//		XMLUnitTestUtils utils = new XMLUnitTestUtils();
//		utils.saveDummyUsersToDB();
//		utils.saveDummyPlacesToDB();
	}
	
	private static void listAll(){
		List<Place> result = null;
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		s.beginTransaction();
		try{
			Criteria c = s.createCriteria(Place.class);
			c.addOrder(Order.desc("creationDate"));
			result = c.list();
			s.getTransaction().commit();
		}catch(HibernateException e){
			s.getTransaction().rollback();
			throw e;
		}
		
//		System.out.println("Length: " + result.size());
//		for (Place place : result) {
//			System.out.println(place.getTitle());
//		}
	}

	private static void listPartial() {
		List<Place> result = null;
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		s.beginTransaction();
		try{
			Criteria c = s.createCriteria(Place.class);
			c.addOrder(Order.desc("creationDate"));
			result = c.setFirstResult(10).setMaxResults(10).list();
			s.getTransaction().commit();
		}catch(HibernateException e){
			s.getTransaction().rollback();
			throw e;
		}
		
//		System.out.println("Length: " + result.size());
//		for (Place place : result) {
//			System.out.println(place.getTitle());
//		}
	}
}